package com.meryoung.day2;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class IframeTest {
    WebDriver driver;
    @BeforeMethod
    public void openchromeTest01(){
        //设置chromedriver路径
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\123\\IdeaProjects\\selenium1\\drivers\\chromedriver.exe");
        //实例化Chromedriver
        driver = new ChromeDriver();
    }
    /*
 打开ui自动化测试页面
 点击iframe的百度链接
  */
    @Test
    public void iframeTest() throws InterruptedException {
        driver.get("C:\\Users\\123\\Desktop\\appium\\index.html");
//通过ID或者name方式转交控制权
        //driver.switchTo().frame("aa");
        Thread.sleep(2000);
        //通过webelement方式
        WebElement iframe = driver.findElement(By.tagName("iframe"));
        driver.switchTo().frame(iframe);
        driver.findElement(By.linkText("baidu")).click();
        //driver控制权转交给原来界面
        driver.switchTo().defaultContent();
        driver.findElement(By.linkText("登陆界面")).click();

    }

    @AfterMethod
    public void closedBrowser(){
        driver.quit();
    }
}
